package com.example.hissys.service;

import com.example.hissys.dto.FeedbackRequest;
import com.example.hissys.entity.Feedback;
import com.example.hissys.mapper.FeedbackMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 创建反馈
     */
    @Transactional
    public Feedback createFeedback(FeedbackRequest request) {
        log.info("Creating feedback for user: {}", request.getUserId());

        Feedback feedback = new Feedback();
        feedback.setUserId(request.getUserId());
        feedback.setContent(request.getContent());
        feedback.setPhone(request.getPhone());

        int created = feedbackMapper.create(feedback);
        if (created == 0) {
            throw new RuntimeException("创建反馈失败");
        }

        log.info("Successfully created feedback: {}", feedback);
        return feedback;
    }
} 